﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Scan
{
    public partial class frmSetHandInput : Form
    {
        private OperationClass _operationClass;
        private flManage.WlManger wlmanger;
        private bool IsXian;
        private bool IsDan;
        private string smsJxsid = "";

        public frmSetHandInput(string bzvalue, OperationClass _operationClassvalue,bool _isxian,bool _isdan)
        {
            InitializeComponent();

            this.textBox3.Text = bzvalue;
            _operationClass = _operationClassvalue;
            IsXian = _isxian;
            IsDan = _isdan;
            wlmanger = new global::Scan.flManage.WlManger();
            wlmanger.Url = PublicVar.WLURL;
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            string strReturn = "";

            if (IsXian)
            {
                if (_operationClass == OperationClass.ruku)
                {
                    strReturn = wlmanger.CartonDepositing(PublicVar.cpId,
                                           PublicVar.cpMc,
                                           PublicVar.kfId,
                                           PublicVar.kfMc,
                                           "",
                                           "",
                                           "",
                                           PublicVar.UserId,
                                           textBox3.Text,
                                           textBox1.Text);
                }
                else if (_operationClass == OperationClass.cuku)
                {
                    if (PublicVar.UserJxsDj > 0)
                    {
                        strReturn = wlmanger.Jxs_CartonPools(PublicVar.JxsId, PublicVar.JxsMc, PublicVar.Ph, PublicVar.UserId, textBox3.Text, textBox1.Text);
                    }
                    else
                    {
                        strReturn = wlmanger.CartonPools(PublicVar.JxsId,
                                               PublicVar.JxsMc,
                                               PublicVar.cpId,
                                               PublicVar.cpMc,
                                               PublicVar.Ph,
                                               PublicVar.UserId,
                                               textBox3.Text,
                                               textBox1.Text);
                    }
                }
                else if (_operationClass == OperationClass.tuihuo)
                {
                    if (PublicVar.UserJxsDj > 0)
                    {
                        strReturn = wlmanger.Jxs_CartonReturn(PublicVar.UserIngJxsCode, PublicVar.UserIngJxsName, PublicVar.UserId, PublicVar.BeiZhu, textBox1.Text);
                    }
                    else
                    {
                        strReturn = wlmanger.CartonReturn(PublicVar.kfId,
                                                          PublicVar.kfMc,
                                                          PublicVar.UserId,
                                                          PublicVar.BeiZhu,
                                                          DateTime.Now.ToString(),
                                                          textBox1.Text);
                    }
                }
            }
            else
            {
                if (_operationClass == OperationClass.ruku)
                {
                    strReturn = wlmanger.SigleDepositing(PublicVar.cpId,
                                           PublicVar.cpMc,
                                           PublicVar.kfId,
                                           PublicVar.kfMc,
                                           "",
                                           "",
                                           "",
                                           PublicVar.UserId,
                                           textBox3.Text,
                                           textBox1.Text);
                }
                else if (_operationClass == OperationClass.cuku)
                {
                    if (PublicVar.UserJxsDj > 0)
                    {
                        strReturn = wlmanger.Jxs_SiglePools(PublicVar.JxsId, PublicVar.JxsMc, PublicVar.Ph, PublicVar.UserId, textBox3.Text, textBox1.Text);
                    }
                    else
                    {
                        strReturn = wlmanger.SiglePools(PublicVar.JxsId,
                                                PublicVar.JxsMc,
                                                PublicVar.cpId,
                                                PublicVar.cpMc,
                                                PublicVar.Ph,
                                                PublicVar.UserId,
                                                textBox3.Text,
                                                textBox1.Text);
                    }
                }
                else if (_operationClass == OperationClass.tuihuo)
                {
                    if (PublicVar.UserJxsDj > 0)
                    {
                        strReturn = wlmanger.Jxs_SigleReturn(PublicVar.UserIngJxsCode, PublicVar.UserIngJxsName, PublicVar.UserId, PublicVar.BeiZhu, textBox1.Text);
                    }
                    else
                    {
                        strReturn = wlmanger.SigleReturn(PublicVar.kfId,
                                                          PublicVar.kfMc,
                                                          PublicVar.UserId,
                                                          PublicVar.BeiZhu,
                                                          DateTime.Now.ToString(),
                                                          textBox1.Text);
                    }
                }
            }

            if (strReturn == "1")
            {
                //发送短信
                if (OperationClass.cuku == _operationClass)
                {
                    if (smsJxsid != PublicVar.JxsId)
                    {
                        string[] al = new string[1];
                        al[0] = PublicVar.JxsId;
                        wlmanger.SendSmS(al, 1, PublicVar.COMNAME + " 于 " + DateTime.Now.ToString() + " 给您发货，请注意查收！", PublicVar.COMID, PublicVar.COMID);
                        smsJxsid = PublicVar.JxsId;
                    }

                }

                MessageBox.Show(string.Format("物流码:{0}，操作方式:{1}，成功", textBox1.Text, _operationClass.ToString()));

            }
            else
            {
                MessageBox.Show(string.Format("物流码:{0}，操作方式:{1}，失败,失败原因:{2}", textBox3.Text, _operationClass.ToString(), strReturn));
            }
        }


        private void frmSetHandInput_Load(object sender, EventArgs e)
        {

        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}